import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';
import '../provied/cartmodel.dart';
class OrderListPage extends StatefulWidget {
  Map arguments;
  OrderListPage({Key key,this.arguments}) : super(key: key);

  @override
  _OrderListPageState createState() => _OrderListPageState(arguments: this.arguments);
}

class _OrderListPageState extends State<OrderListPage> with AutomaticKeepAliveClientMixin{
  Map arguments;
  _OrderListPageState({this.arguments});
  List o=[
    {
      "id":1,
      "goodsname":"懒得信那种日久生情 培养感情的一套 浪费时间主要是没感觉",
      "price":"121",
      "type":0,
      "images":"http://dbyxs.xyz:3005/uploads/b593883c3adac89564d762ae7b76ad5e"
    },
    {
      "id":1,
      "goodsname":"懒得信那种日久生情 培养感情的一套 浪费时间主要是没感觉",
      "price":"1221",
      "type":1,
      "images":"http://dbyxs.xyz:3005/uploads/b593883c3adac89564d762ae7b76ad5e"
    },
    {
      "id":1,
      "goodsname":"懒得信那种日久生情 培养感情的一套 浪费时间主要是没感觉你是不是又给我买东西了啊",
      "price":"141",
      "type":2,
      "images":"http://dbyxs.xyz:3005/uploads/b593883c3adac89564d762ae7b76ad5e"
    },
    {
      "id":1,
      "goodsname":"懒得信那种日久生情 培养感情的一套 浪费时间主要是没感觉",
      "price":"11",
      "type":3,
      "images":"http://dbyxs.xyz:3005/uploads/b593883c3adac89564d762ae7b76ad5e"
    },
    {
      "id":1,
      "goodsname":"不早了睡觉的 明天早班",
      "price":"161",
      "type":4,
      "images":"http://dbyxs.xyz:3005/uploads/b593883c3adac89564d762ae7b76ad5e"
    },
  ];
  List orderlist=[];
  @override
  void initState(){
    super.initState();
      //this.getlist();
    // _getorders();
      setState(() {
        // context.read<CartProvide>().getOrder();
      });
    //print(watch<CartProvide>().goodsAdd);
  // print(context.watch<CartProvide>().goodsAdd);
  }
 
  // void getlist(){
  //   // List h=context.watch<CartProvide>().goodsAdd;
  //  // print(context.watch<CartProvide>().goodsAdd);
  //   o.forEach((item) {
  //     if(this.arguments['id']==0){
  //       setState(() {
  //         this.orderlist.add(item);
  //       //   print(orderlist);
  //      });
  //     }else if(item['type']==this.arguments['id']){
  //       print(item);
  //      setState(() {
  //         this.orderlist.add(item);
  //          print(orderlist);
  //      });

  //     }
  //   });
  // }
  void _getgoods()async{
    List o=context.watch<CartProvide>().goodsAdd;
   // print(o);
   this.orderlist.clear();
    o.forEach((item) {
      if(this.arguments['id']==0){
        setState(() {
          
          this.orderlist.add(item);
        //   print(orderlist);
       });
      }else if(item['type']==this.arguments['id']){
       // print(item);
       setState(() {
        // this.orderlist.clear();
          this.orderlist.add(item);
          // print(orderlist);
       });

      }
    });
//print('订单${context.watch<CartProvide>().goodsAdd}');
  }
  List <Widget> _getorders()=>List.generate(1, (index) {
    print(context.watch<CartProvide>().goodsAdd);
    _getgoods();
    return Text('你还');
  });
  List <Widget> _getorder()=>List.generate(orderlist.length, (index) {
   
     
    return Container(
      height: ScreenUtil().setHeight(450),
      child: 
    InkWell(
      onTap: (){
        Navigator.pushNamed(context, '/orderdetail',arguments: {"id":this.orderlist[index]});
      },
      child:   Card(
        child: Column(
          children: <Widget>[
            //订单头部区域
            Container(
              width: ScreenUtil().setWidth(730),
              height: ScreenUtil().setHeight(90),
              padding: EdgeInsets.only(top:15),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  SizedBox(width: 15,),
                  Expanded(
                    flex: 4,
                    child: Text('小仙女的私人店铺哦',style: TextStyle(fontSize:14,fontWeight: FontWeight.w600),)),
                    Expanded(
                      flex: 1,
                      child: Center(child: IconButton(icon: Icon(Icons.chevron_right,color: Colors.black26,), onPressed: null),),),
                      SizedBox(width: 35,),
                      Expanded(
                        flex: 2,
                        child: this.orderlist[index]['type']==1?Text('代付款',style: TextStyle(color:Colors.orangeAccent),):(this.orderlist[index]['type']==2?
                        Text('待发货',style: TextStyle(color:Colors.orangeAccent),):(this.orderlist[index]['type']==3?
                        Text('待收货',style: TextStyle(color:Colors.orangeAccent)):Text('待评价',style: TextStyle(color:Colors.orangeAccent)))
                        )
                        )
                ],
              ),
            ),
            //订单主题区域
            Container(
              height: ScreenUtil().setHeight(200),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  SizedBox(width: 15,),
                    Container(
                      width: ScreenUtil().setWidth(200),
                      height: ScreenUtil().setHeight(200),
                      //http://dbyxs.xyz:3005/uploads/b593883c3adac89564d762ae7b76ad5e
                      child: Image.network(orderlist[index]['images'],fit:BoxFit.cover),
                    ),
                    Container(
                      padding: EdgeInsets.all(5),
                      width: ScreenUtil().setWidth(350),
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.start,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          Text('${orderlist[index]['goodsname']}',maxLines: 2,overflow: TextOverflow.ellipsis,),
                          Text('${orderlist[index]['size']}',style: TextStyle(fontSize:12,color:Colors.black26),maxLines: 2,overflow: TextOverflow.ellipsis,)
                        ],
                      )
                    ),
                    Container(
                      width: ScreenUtil().setWidth(140),
                      padding: EdgeInsets.all(5),
                      //flex: 1,
                      child: Column(
                       // mainAxisAlignment: MainAxisAlignment.end,
                       crossAxisAlignment: CrossAxisAlignment.end,
                        children: <Widget>[
                          Text('￥${orderlist[index]['price']}'),
                          Text('x ${orderlist[index]['count']}',style: TextStyle(fontSize:10,color:Colors.black26),)
                        ],
                      )
                    )
                ],
              ),
            ),
            Container(
              padding: EdgeInsets.all(5),
              width: ScreenUtil().setWidth(730),
              height: ScreenUtil().setHeight(80),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.end,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Text('总价:￥${ double.parse(orderlist[index]['price'])*double.parse(orderlist[index]['count'])}',style: TextStyle(color:Colors.black26),),
                  SizedBox(width: 5,),
                  Text('实付款￥${double.parse(orderlist[index]['price'])*double.parse(orderlist[index]['count'])}',)
                ],
              ),
            ),
           Expanded(
             flex: 1,
             child:  Container(
               // margin: EdgeInsets.all(5),
              width: ScreenUtil().setWidth(730),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.end,
                mainAxisAlignment: MainAxisAlignment.end,
                children: <Widget>[
                  this.orderlist[index]['type']==1? Container(
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(10)
                    ),
                    child: OutlineButton(onPressed: (){
                       var data={
                        "id":this.orderlist[index]['id'],
                        "type":2
                      };
                     setState(() {
                        context.read<CartProvide>().getdeliver(data);
                          context.read<CartProvide>().getOrder();
                     });
                    },child:Text('付款'),splashColor: Colors.black26,borderSide: BorderSide(color:Colors.black26),),
                  ): Text(''),
                 this.orderlist[index]['type']==2? Container(
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(10)
                    ),
                    child: OutlineButton(onPressed: (){
                      var data={
                        "id":this.orderlist[index]['id'],
                        "type":0
                      };
                      context.read<CartProvide>().getdeliver(data);
                    },child:Text('退货'),splashColor: Colors.black26,borderSide: BorderSide(color:Colors.black26),),
                  ): Text(''),
                  // Container(
                  //   decoration: BoxDecoration(
                  //     borderRadius: BorderRadius.circular(10)
                  //   ),
                  //   child: OutlineButton(onPressed: (){},child:Text(''),splashColor: Colors.black26,borderSide: BorderSide(color:Colors.black26),),
                  // ),
                  this.orderlist[index]['type']==3?Container(
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(10)
                    ),
                    child: OutlineButton(onPressed: (){},child:Text('查看物流',style: TextStyle(color:Colors.black26),),splashColor: Colors.black26,borderSide: BorderSide(color:Colors.black26),),
                  ):Text(''),
                  SizedBox(width: 10,height: 3,),
                  this.orderlist[index]['type']==3?Container(
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(10)
                    ),
                    child: OutlineButton(onPressed: (){
                       var data={
                        "id":this.orderlist[index]['id'],
                        "type":4
                      };
                      context.read<CartProvide>().getdeliver(data);
                      setState(() {
                        context.read<CartProvide>().getOrder();
                      });
                    },child:Text('确认收货',style: TextStyle(color:Colors.orangeAccent),),splashColor: Colors.black26,borderSide: BorderSide(color:Colors.orangeAccent),),
                  ):(this.orderlist[index]['type']==0|4?Container(
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(10)
                    ),
                    child: OutlineButton(onPressed: (){},child:Text('评价',style: TextStyle(color:Colors.orangeAccent),),splashColor: Colors.black26,borderSide: BorderSide(color:Colors.orangeAccent),),
                  ):Text(''))
                ],
              ),
              // height: ScreenUtil().setHeight(70),
            ))
          ],
        ),
      ),
    )
    );
  });
  @override
  bool get wantKeepAlive => true;
  @override
  Widget build(BuildContext context) {
    // _getgoods();
    _getorders();
    if(orderlist==null){
      return Container(
        child: Scaffold(
          body: Center(child:Text('数据加载中')),
        ),
      );
    }else{
      return Container(
      width: ScreenUtil().setWidth(730),
      height: double.infinity,
       child: ListView(
         children: <Widget>[
           Column(
             children: _getorder()
            //  <Widget>[
               
            //    //Text('我是订单列表${this.arguments['id']}')
            //  ],
           )
         ],
       ),
    );
    }
  }
}